<template>
	<view>
    <!-- 收货地址的盒子 -->
		<div class="top" v-if="JSON.stringify(address)==='{}'">
        <button size="mini" plain="true" @click='sitebtn' >请设置收货地址+</button>
    </div>
    <!-- 渲染收货信息的盒子 -->
     <div class="box-info" v-else>
         <div class="rou1">
           <div class="rou1-left">
                收货人: {{address.userName}}
           </div>
           <div class="rou1-right">
               <div class="phone">电话:{{address.telNumber}}</div>
               <uni-icons type="arrowright"></uni-icons>
           </div>
         </div>
       <div class="rou2">
         <div class="rou2-left">收货地址: </div>
         <div class="rou2-right"> {{address.provinceName}} {{address.cityName}}-{{address.countyName}}-{{address.detailInfo}}</div>
        
       </div>
     </div>
      <div class="fool">
        <image src="../../static/shopping.png"  class="imgshop"></image>
      </div>
	</view>
</template>

<script>
  import { mapState,mapMutations} from 'vuex'
	export default {
		data() {
			return {
				// adduser:{ }
			};
		},
    computed:{
      ...mapState('m_user',['address'])
    },
    methods:{
      ...mapMutations('m_user',['updateAddress',]),
      //用户地址信息储存
     async sitebtn(){
       const [err,succ] = await uni.chooseAddress().catch(err => err)
     if(err === null && succ.errMsg === "chooseAddress:ok"){
       console.log(succ,11)
        this.updateAddress(succ)
         }
           console.log(err,succ)
         if(err &&(err.errMsg === "chooseAddress:fail auth deny"||err.errMsg === 'chooseAddress:fail authorize no response')) {
           console.log('需要重新授权')
           this.reAuth()
         }
      },
      //用户重新授权
     async reAuth(){
        const [err, res] = await uni.showModal({
          content:'检测到您没打开地址权限,是否去设置打开?',
          confirmText:'确认1',
          cancelText:'取消'
        })
          // console.log(err,res,555)
           if(err) return 
           // if(res.cancel) return  uni.$showMsg('您取消了授权')
            if(res.cancel) return  uni.openSetting({
              success(res){
                console.log(res,123123)
              }
            })
            if(res.confirm) return    uni.getSetting({
             success: (res )=>{
               console.log(res,654321)
               if(res.authSetting['scope.address']) return uni.$showMsg('用户授权成功')
             }
           })
         }
    }
	}
</script>

<style lang="less">
  .top{
    width: 100%;
    height:70px;
  padding-top: 30px;
  display:flex;
    button{
       width: 170px;
       height: 40px;
       line-height: 40px;
       border: none;
      background-color: #119513;
         color:  #FFFFFF;
     }
    }
    .box-info{
      padding: 20px 8px;
      font-size: 14px;
         .rou1{
           display: flex;
           justify-content: space-between;
             .rou1-left{}
             .rou1-right{
               display: flex;
               .phone{}
               
             }
         }
         .rou2{
           display: flex;
           margin: 10px 0;
         }
      
      }
  .fool{

    .imgshop{
      width:100%;
      height:20px
    }
  }

</style>
